package com.example.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.ValueFilter;
import com.alibaba.fastjson.support.config.*;
import com.example.config.FastJSON_Config;

public class BaseController {
    final static String _DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
    protected void outString(String json, HttpServletResponse response) {
        PrintWriter writer = null;
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        try {
            writer = response.getWriter();
            writer.write(json);
            writer.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (null != writer) {
                writer.close();
                writer = null;
            }
        }
    }

    public void writeJson(Object object, HttpServletResponse response){
        try {
            System.out.println("完美==>" + object);
            String json = FastJSON_Config.objectToJSON(object);//JSON.toJSONStringWithDateFormat(object, "yyyy-MM-dd HH:mm:ss");
            System.out.println("被===>" + json);
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write(json);
            response.getWriter().flush();
            response.getWriter().close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}




